package com.future.mayi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.future.mayi.dialog.GoodsSkuDialog;
import com.future.mayi.model.GoodsBatchModel;
import com.future.mayi.model.interfaces.GoodsBatchItemListener;
import com.future.mayi.view.GoodsBatchItemView;


public class GoodsBatchAdapter extends BaseRecyclerViewAdapter<GoodsBatchModel> implements GoodsBatchItemListener {

    public GoodsBatchAdapter(Context context) {
        super(context, null);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(new GoodsBatchItemView(mContext));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        ViewHolder holder = (ViewHolder) viewHolder;
        holder.itemView.setListener(this);
        holder.itemView.setModel(getItem(position), position);
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        GoodsBatchItemView itemView;

        public ViewHolder(View itemView) {
            super(itemView);
            this.itemView = (GoodsBatchItemView) itemView;
        }
    }

    @Override
    public void deleteItem(GoodsBatchItemView itemView) {
        delete(itemView.getPosition());
    }


    private GoodsSkuDialog goodsSkuDialog;

    @Override
    public void showAddGoods(GoodsBatchItemView itemView) {
        if (goodsSkuDialog == null) {
            goodsSkuDialog = new GoodsSkuDialog(mContext);
        }
        goodsSkuDialog.show(itemView);
    }

}
